home *** CD-ROM | disk | FTP | other *** search
- /*
- * rmdir.cmm
- *
- * This .CMM file implements a DOS-like RD command.
- */
-
- #include "Netware.lib"
-
- usage()
- {
- printf("Use the RD command to remove an empty directory.\n");
- printf("Syntax:\n");
- printf(" RD [drive:][path]\n");
- printf("where:\n");
- printf(" drive:/path Specifies the directory to remove. It must be empty.\n");
- exit(EXIT_FAILURE);
- }
-
- /* ---------------------------------------------------------------------- */
-
- DeleteDirectory(pDirSpec)
- {
- lReg.ah = 0x3A;
- if !defined(_DOS32_)
- lReg.ds = segment(pDirSpec), lReg.dx = offset(pDirSpec);
- else
- lReg.dx = pointer(pDirSpec);
- return interrupt(0x21,lReg);
- }
-
- myrmdir(dir)
- {
- if( defined(_NWNLM_) ) return rmdir(dir);
- if( defined(_OS2_) )
- {
- #define ORD_DOS32DELETEDIR 226
- return DynamicLink("DOSCALLS",ORD_DOS32DELETEDIR,BIT32,CDECL,dir);
- }
- if( defined(_NTCON_) || defined(_NTWIN_) )
- {
- return !DynamicLink("KERNEL32","RemoveDirectoryA",STDCALL,dir);
- }
- if( defined(_DOS_) || defined(_WINDOWS_) || defined(_DOS32_) )
- {
- return !DeleteDirectory(dir);
- }
-
- printf("Rmdir.cmm does not support this version of CEnvi.\n");
- return 1;
- }
-
- /* ---------------------------------------------------------------------- */
-
- main(argc,argv)
- {
- if( argc!=2 ) usage();
- if( !strcmp(argv[1],"/?") ) usage();
-
- source = argv[1];
-
- dest = Directory(source);
- if( dest==NULL )
- {
- if( isalpha(source[0]) && source[1]==':' &&
- (source[2]=='\0' || source[2]=='/' || source[2]=='\\') )
- {
- printf("You may not remove volume \"%s\".\n",source);
- } else {
- printf("There is no directory named \"%s\".\n",source);
- }
- exit(EXIT_FAILURE);
- } else {
- if( GetArraySpan(dest)!=0 )
- {
- printf("You may not specify more than one directory.\n");
- exit(EXIT_FAILURE);
- }
- if( (dest[0].attrib & _A_SUBDIR)==0 )
- {
- printf("\"%s\" is not a directory.\n",source);
- exit(EXIT_FAILURE);
- }
- }
-
- strcpy(tmp,source);
- if( tmp[strlen(tmp)-1]!='/' ) strcat(tmp,"/");
- strcat(tmp,"*.*");
- if( Directory(tmp) )
- {
- printf("\"%s\" cannot be removed; directory not empty.\n",source);
- exit(EXIT_FAILURE);
- }
- if( myrmdir(source) )
- {
- printf("\"%s\" was not removed.\n",source);
- }
- exit(EXIT_SUCCESS);
- }
-